/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dk.rofl.items;

import java.util.ArrayList;
import rofl.Utils;

/**
 *
 * @author menderleit
 */
public class GameChest {

    // Items in the chest.
    private ArrayList<GameItem> items;
    private int gold;

    // Constructor.
    public GameChest() {
        items = new ArrayList();
        gold = 0;
    }

    // Set the amount of gold in this chest.
    public void setGoldAmount(int gold) {
        if (gold > 0) {
            this.gold = gold;
        }
    }

    // Get the gold in this chest.
    public int getGold() {
        return gold;
    }

    // Add an item to the chest.
    public void addItem(GameItem item) {
        items.add(item);
    }

    // Get the items in this chest.
    public ArrayList<GameItem> getItems() {
        return items;
    }

    // Randomly generate a chest.
    public static GameChest generateChest(int itemLevel) {
        GameChest gc = new GameChest();

        // Generate some gold.
        gc.setGoldAmount(itemLevel + Utils.rnd().nextInt(itemLevel * 5));
        
        // Generate 1-3 items.
        int r = Utils.rnd().nextInt(3) + 1;
        for(int i=0; i<r; i++) {
            GameItem gi = null;
            int it = GameItem.generateItemType();
            switch(it) {
                case GameItem.TYPE_ARMOR:
                    // Create an Armor item.
                    gi = Armor.generateArmor(itemLevel, Equipment.generateItemQuality());
                    break;
                case GameItem.TYPE_POTION:
                    // Create a Health potion.
                    gi = new HealthPotion(itemLevel);
                    break;
                case GameItem.TYPE_WEAPON:
                    // Create a Weapon item.
                    gi = Weapon.generateWeapon(itemLevel, Equipment.generateItemQuality());
                    break;
            }
            gc.addItem(gi);
        }
        
        return gc;
    }
}
